<? 
include ("../../core.php5/Security/User.class.php"); #this line has to be the first one because of the session_start();
include("../../core.php5/DB/ORM.class.php");
include("../../core.php5/Grid.class.php");
include("../../core.php5/DB/DataBase.class.php");
include("../../core.php5/GridSource.class.php");
include("../../core.php5/GridPresenter.class.php");
include("../../core.php5/GUI/HtmlLink.class.php");
include("../../core.php5/GUI/ComboBox.class.php");
include("../../core.php5/GridLinker.class.php");
include "../../core.php5/GridSorter.class.php";
include "../../core.php5/GridSortPage.class.php";
include("../../core.php5/Utilities/Application.class.php");

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src="../../ckeditor/ckeditor.js"></script>
<script type="text/javascript" >

function setContentValue()
{
	var c=document.getElementById("contents");
	c.value=CKEDITOR.instances.contents.getData();
}

</script>

</head>
<?php 


/*if ( isset( $_POST ) )
	$postArray = &$_POST ;			// 4.1.0 or later, use $_POST
else
	$postArray = &$HTTP_POST_VARS ;	// prior to 4.1.0, use HTTP_POST_VARS

foreach ( $postArray as $sForm => $value )
{
	if ( get_magic_quotes_gpc() )
		$postedValue = htmlspecialchars( stripslashes( $value ) ) ;
	else
		$postedValue = htmlspecialchars( $value ) ;

	echo $sForm." --- ".$postedValue."<br>";
}*/

if($_POST)
{

	USER::VerifySecurity();
	
	$usr=$_SESSION['user'];
	$q="INSERT INTO news VALUES (null, '".$_POST['title']."','".$_POST['contents']."',".$_POST['ambit'].",'".substr($_POST['fddate'],6,4)."-".substr($_POST['fddate'],0,2)."-".substr($_POST['fddate'],3,2)."',".htmlspecialchars($usr->id)." )";
	//echo $q;
	$res = DataBase::ExecuteNonQuery($q);
	if($res)
		echo '<div style="background-color:green;text-align:center;color:white"><b>Guardado correctamente</b></div> <script>get("select/noticias.php","content");</script>';
	else
		echo '<div style="background-color:red;text-align:center;color:white">Error al Guardar</div>';
	
	

}
else
{
?>
<body>
<form method="post" action="" name="miform">
	<div id="">
	<a href="javascript:;" onClick="get('select/noticias.php','content')" class="agregar">Regresar</a><br />
	<table border="0" style="border:1px #000000 solid" ><tr><td align="center"><h3>Agregar Publicaci&oacute;n</h3>
	<table align="center" border="0" cellpadding="1" cellspacing="1" style="width: 100%;">
			<tbody>
				<tr>
					<td>
					Titulo
						<input id="c" name="title" type="text" style="width:99%" /></td>
				</tr>
				<tr>
					<td>Contenido
						<textarea cols="80" id="contents" name="contents" rows="10"></textarea></td>
						  <script>
               					 CKEDITOR.replace( 'contents' );
            			 </script>
				</tr>
				<tr>
					<td>
						Tipo 
						
						<?php 
							$cmb = new Combo();
							$cmb->AddItem("0","Selecciona..");
							$cmb->FillDB("SELECT * FROM ambits","idambits");
							$cmb->Render("ambit")
						?>
						
						</td>
				</tr>
				<tr>
				
					
					<td>	Fecha
						<input id="fddate" name="fddate" type="text" value="mm/dd/aaaa" /></td>
						<script> datepick("fddate","option|dateFormat|yyyy-mm-dd"); </script>
				</tr>
				<tr>
					<td align="center" >
						<input name="enviar" type="button" onclick="setContentValue(); post('insert/noticias.php?a=ins', 'mensajes','miform'); get('select/noticias.php','content'); $('#mensajes').empty(); $('#mensajes').show(); desaparece('mensajes');" value="Guardar" />
						<input name="cancelar" onclick="get('select/noticias.php','content');" type="button" value="Cancelar" /></td>
				</tr>
			</tbody>
		</table>
		
			</td></tr>
	</table>
	</div>
 </form>
</body>
<?php } ?>
</html>